﻿using System.Collections.Generic;
using UnityEngine;
/*参考答案*/
public class PingPongColor : MonoBehaviour
{
    private Color[] colors;
    int i = 0;
    int direction = 1;
    private void Start()
    {
        colors = new Color[] { Color.red, Color.green, Color.blue, Color.yellow, };
        this.gameObject.GetComponent<MeshRenderer>().material.color = Color.red;
    }
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            i += direction;
            this.gameObject.GetComponent<MeshRenderer>().material.color = colors[i];
            if (i==(colors.Length-1)||i==0)
            {
                direction *= -1;
            }
        }
    }
}
